//
//  YHYAddViewController.m
//  Home
//
//  Created by 杨泓晔 on 16/4/27.
//  Copyright © 2016年 LanJue. All rights reserved.
//

#import "YHYAddViewController.h"
#import "YHYDesignerPTableViewCell.h"
#import "WSShopInfoNextView.h"
#import "DCPaymentView.h"
#import "WSCustomPickerView.h"
#import "AppDelegate.h"
#import "YHYSelectViewController.h"
#import "TZTestCell.h"
//#import "YHYSeaPictureViewController.h"
#import "TZImagePickerController.h"
//#import "UIView+Five.h"
#import "UIView+Layout.h"
#import "YHYDesignRequireTableViewCell.h"
#import "YHYStyleTableViewCell.h"
#import "YHYButtonTableViewCell.h"
#import "SeaPictureViewController.h"
#import "YHYPictureCollectionViewCell.h"
@interface YHYAddViewController ()<UITableViewDataSource,UITableViewDelegate,WSCustomPickerViewDelegate,UITableViewDelegate,UITableViewDataSource,YHYSelectViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate,TZImagePickerControllerDelegate,YHYButtonTableViewdelegate>{
    NSInteger index;
    CGFloat _itemWH;
    CGFloat _margin;
    
    NSMutableArray *_selectedAssets;
    NSInteger num;
    NSInteger a;
    NSIndexPath *indexP;
}
@property (nonatomic,strong)UITableView *myTableView;
@property (nonatomic,strong)NSArray *array;
@property (nonatomic,strong)NSArray *arrTwo;
@property (nonatomic,strong)NSString *name;
@property (nonatomic,strong)WSCustomPickerView *customPicker;
@property (nonatomic,strong)NSString *styleL;
@property (nonatomic,strong)NSString *addressL;
@property (nonatomic,strong)NSString *sizeL;
@property (nonatomic,strong)NSString *xiL;
@property (nonatomic,strong)NSString *styleRequire;
@property (nonatomic,strong)NSString *yearL;
@property (nonatomic,strong)NSString *priceL;

@property (nonatomic,strong)YHYSelectViewController *yhy;
//@property (nonatomic,retain)TZTestCell *cell;

@property (nonatomic,strong)AppDelegate *myAppDelegate;
@property (nonatomic,strong)UIView *myBackBigView;
//@property (nonatomic,strong)NSMutableArray *mycollectionVArray;


@property (nonatomic,assign)NSInteger selectArray;
@property (nonatomic,strong)UICollectionViewFlowLayout *layout;
@property (nonatomic,strong)UICollectionView *myCollectionView;
@property (nonatomic,strong)UILabel *numLabel;
@property (nonatomic,strong)UIButton *button;


@property (nonatomic,retain)NSIndexPath *myindexPath;
@property (nonatomic,retain)NSMutableArray *seaArr;
@property (nonatomic,retain)UILabel *textnameL;
@property (nonatomic,retain)NSIndexPath *tapIndexPath;

@end

@implementation YHYAddViewController

- (void)viewWillAppear:(BOOL)animated {
    
    //    self.navigationController.navigationBarHidden = NO;
    self.title = @"添加任务";
    self.tabBarController.tabBar.hidden = YES;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(change:) name:@"arr" object:nil];
    self.tabBarController.tabBar.hidden=YES;
    
    self.navigationController.navigationBar.translucent = YES;
    
<<<<<<< HEAD
=======
    
    
    

>>>>>>> 982ccfb85b77eadfd5494c8f30bd3225dd4fe1c6
    [self.myCollectionView reloadData];
}

-(void) viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden=NO;
}

- (void)viewDidLoad {
    //self.view.backgroundColor = [UIColor redColor];
    //    左侧的图标
    self.selectedPhotos = [NSMutableArray array];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(Back:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    self.layout = [[UICollectionViewFlowLayout alloc] init];
    _margin = 4 * AUTO_HEIGHT;
    _itemWH = (self.view.tz_width - 20 * AUTO_WIDTH-2 * _margin - 7) / 3 - _margin;
    self.layout.itemSize = CGSizeMake(_itemWH, _itemWH  - 1 );
    self.layout.minimumInteritemSpacing = _margin;
    self.layout.minimumLineSpacing = 10  * AUTO_HEIGHT ;
    _myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0 * AUTO_WIDTH, SCREEN_WIDTH, _itemWH * 3 + _margin + 6 * AUTO_HEIGHT + 50 * AUTO_HEIGHT- 15 * AUTO_HEIGHT) collectionViewLayout:self.layout];
    self.numLabel = [UILabel new];
    
    
    
    
    _selectedAssets = [NSMutableArray array];
    self.myindexPath = [NSIndexPath new];
    _seaArr = [NSMutableArray array];
    self.numLabel = [UILabel new];
    self.tapIndexPath = [NSIndexPath new];
    
    [self creatView];
    
    
}

- (void)creatView{
    self.array = [NSArray arrayWithObjects:@"任务名称", @"任务类型",@"任务地址",@"任务面积（㎡）",nil];
    
    _arrTwo = [NSArray arrayWithObjects:@"设计经验",@"项目总价（元）",@"详细描述", nil ];
<<<<<<< HEAD
    //    self.mycollectionVArray = [NSMutableArray arrayWithObjects:@"aa",@"vvv",@"不知道",@"sssss",@"任务名", nil];
    
=======
>>>>>>> 982ccfb85b77eadfd5494c8f30bd3225dd4fe1c6
    
    
    self.myTableView = [UITableView new];
    
    [self.view addSubview:self.myTableView];
    self.myTableView.rowHeight = 50 * AUTO_HEIGHT;
    
<<<<<<< HEAD
    //    UIView *fod = [UIView new];
    //    fod.frame = CGRectMake(0, 0, SCREEN_WIDTH, 15);
    //    self.myTableView.tableFooterView = fod;
=======
    self.myTableView.separatorStyle = UITableViewCellSelectionStyleNone;

//    UIView *fod = [UIView new];
//    fod.frame = CGRectMake(0, 0, SCREEN_WIDTH, 15);
//    self.myTableView.tableFooterView = fod;
>>>>>>> 982ccfb85b77eadfd5494c8f30bd3225dd4fe1c6
    //self.myTableView.separatorStyle = UITableViewCellSelectionStyleNone;
    [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view);
        make.left.mas_equalTo(self.view);
        make.height.mas_equalTo(self.view.frame.size.height + 50 * AUTO_HEIGHT);
        make.width.mas_equalTo(self.view);
        
    }];
    //_myTableView.scrollEnabled = NO;
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.myTableView.backgroundColor = LV;
    [self.myTableView registerClass:[YHYDesignerPTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.myTableView registerClass:[YHYDesignRequireTableViewCell class] forCellReuseIdentifier:@"YHYDesignRequireTableViewCell"];
    [self.myTableView registerClass:[YHYStyleTableViewCell class] forCellReuseIdentifier:@"YHYStyleTableViewCell"];
    [self.myTableView registerClass:[YHYButtonTableViewCell class] forCellReuseIdentifier:@"YHYButtonTableViewCell"];
    [self.myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"ce"];
    [[UITableViewHeaderFooterView appearance] setTintColor:LV];
    
    [_myTableView reloadData];
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 6;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    if (section == 0) {
        
        return 8 * AUTO_HEIGHT;
    }
    
    if (section == 1) {
        
        return 8 * AUTO_HEIGHT;
    }
    if (section == 2) {
        return 8 * AUTO_HEIGHT;
    }
    if (section == 3) {
        return 8 * AUTO_HEIGHT;
    }
    
    return 0;
}

<<<<<<< HEAD
//  后加的

//- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
//
//    CGFloat sectionHeaderHeight = 0;//设置你footer高度
//    if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
//        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
//    } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
//        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
//    }
//
//}
//
=======
>>>>>>> 982ccfb85b77eadfd5494c8f30bd3225dd4fe1c6

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return _array.count;
    }
        if (section == 1) {
        return 1;
    }
    if (section == 2) {
        return 1;
    }
    if (section == 3) {
        return _arrTwo.count;
    }
    if (section == 4) {
        return 1;
    }
    if (section == 5) {
        return 1;
    }
    return 0;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *str = @"cell";
    YHYDesignerPTableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:str];
    
    cell2.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.section ==0) {
        cell2.xmLabel.text = _array[indexPath.row];
        if (indexPath.row == 0) {
            
            if (_name != nil) {
                
                cell2.WXlabel.text = _name;
                
            }
            else{
                
//                       cell2.WXlabel.text = [NSString stringWithFormat:@"必填"];
            }
            
        }
        
        
        if (indexPath.row == 1) {
            if (_styleL != nil) {
                cell2.WXlabel.text = _styleL;
            }
            else{
                //            cell.WXlabel.text = [NSString stringWithFormat:@"必填"];
            }
        }
        
        if (indexPath.row == 2) {
            if (_addressL != nil) {
                cell2.WXlabel.text = _addressL;
                
            }
            else{
                //                cell.WXlabel.text = [NSString stringWithFormat:@"必填"];
            }
        }
        //        if (indexPath.row ==4) {
        //            if (_xiL !=nil) {
        //                cell2.WXlabel.text=_xiL;
        //            }
        //            else{
        //                //                cell.WXlabel.text=[NSString stringWithFormat:@"必填"];
        //            }
        //        }
        
        if (indexPath.row == 3) {
            if (_sizeL != nil) {
                cell2.WXlabel.text = _sizeL;
            }
            else{
                //                 cell.WXlabel.text = [NSString stringWithFormat:@"必填"];
            }
        }
        
    }
    
    
    if  (indexPath.section == 1){
        
        if (indexPath.row == 0) {
            YHYDesignRequireTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YHYDesignRequireTableViewCell"];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
            
        }
        
    }
    //风格要求
    if (indexPath.section == 2) {
        YHYStyleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YHYStyleTableViewCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    
    if (indexPath.section == 3) {
        static NSString *str = @"cell";
        YHYDesignerPTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
        cell.xmLabel.text = _arrTwo[indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (indexPath.row == 0) {
            if (_yearL != nil) {
                
                
                cell.WXlabel.text = _yearL;
                
            }
            else{
                //  cell.WXlabel.text = [NSString stringWithFormat:@"必填"];
            }
            
        }
        if (indexPath.row == 1) {
            if (_priceL !=nil) {
                cell.WXlabel.text = _priceL;
            }
            else{
                // cell.WXlabel.text = [NSString stringWithFormat:@"必填"];
            }
            
        }
        if (indexPath.row == 2) {
            if (_textnameL !=nil) {
                cell.WXlabel.text = @"已填";
            }
            else{
                // cell.WXlabel.text = [NSString stringWithFormat:@"必填"];
            }
            
        }
        if (indexPath.row == 3) {
            
        }
        
        return cell;
        
    }
    
    //图片
    if (indexPath.section == 4) {
        UITableViewCell *cell3 = [tableView dequeueReusableCellWithIdentifier:@"ce" forIndexPath:indexPath];
        
        
        
        cell3.selectionStyle = UITableViewCellSelectionStyleNone;
        cell3.backgroundColor = LV;
        indexP = indexPath;
<<<<<<< HEAD
        cell.backgroundColor = LV;
        self.layout = [[UICollectionViewFlowLayout alloc] init];
        _margin = 4 * AUTO_HEIGHT;
        _itemWH = (self.view.tz_width - 20 * AUTO_WIDTH-2 * _margin - 7) / 3 - _margin;
        self.layout.itemSize = CGSizeMake(_itemWH, _itemWH  - 1 );
        self.layout.minimumInteritemSpacing = _margin;
        self.layout.minimumLineSpacing = 10  * AUTO_HEIGHT ;
        if (_selectedPhotos.count < 3 ) {
            a = 0;
        }
        if (_selectedPhotos.count >= 3 && _selectedPhotos.count <= 5) {
            a = 1;
        }
        if ( _selectedPhotos.count > 5 && _selectedPhotos.count <= 9) {
            a = 2;
        }
        
        
        NSLog(@"777=%ld",_selectedPhotos.count);
        NSLog(@"888=%ld",a%2);
        _myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0 * AUTO_WIDTH, SCREEN_WIDTH, 150 * AUTO_HEIGHT  + (150 * AUTO_HEIGHT* (a))) collectionViewLayout:self.layout];
=======
        cell3.backgroundColor = LV;
        
        
        
>>>>>>> 982ccfb85b77eadfd5494c8f30bd3225dd4fe1c6
        self.myCollectionView.backgroundColor = [UIColor whiteColor];
        //    裁掉view的边界
        self.myCollectionView.layer.masksToBounds = NO;
        //    设置半径
        //self.myCollectionView.layer.cornerRadius = 6 * AUTO_WIDTH;
        self.myCollectionView.scrollEnabled = NO;
        // self.myCollectionView.backgroundColor = [UIColor whiteColor];
<<<<<<< HEAD
        [cell addSubview:_myCollectionView];
        UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(15*AUTO_WIDTH, 6 * AUTO_HEIGHT, 200, 20 *AUTO_HEIGHT)];
        titleLabel.text = @"参考图片";
        titleLabel.alpha = 0.6;
        titleLabel.font = [UIFont systemFontOfSize:15];
        [cell addSubview:titleLabel];
        
        UILabel *line = [[UILabel alloc]init];
        line.backgroundColor = [UIColor blackColor];
        [cell addSubview:line];
        line.alpha = 0.3;
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(titleLabel.mas_bottom).offset(5);
            make.left.equalTo(cell).offset(15.00*AUTO_WIDTH);
            make.size.mas_equalTo(CGSizeMake(KScreenWidth - 15.00*AUTO_WIDTH, 0.5));
            
        }];
=======
        [cell3 addSubview:_myCollectionView];
>>>>>>> 982ccfb85b77eadfd5494c8f30bd3225dd4fe1c6
        
        _myCollectionView.contentInset = UIEdgeInsetsMake(40 * AUTO_WIDTH, 15 * AUTO_HEIGHT, 5 * AUTO_WIDTH, 15 * AUTO_HEIGHT);
        _myCollectionView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, -2 * AUTO_HEIGHT);
        _myCollectionView.dataSource = self;
        _myCollectionView.delegate = self;
        _myCollectionView.backgroundColor = [UIColor whiteColor];
        [_myCollectionView registerClass:[TZTestCell class] forCellWithReuseIdentifier:@"TZTestCell"];
        
        [_myCollectionView registerClass:[YHYPictureCollectionViewCell class] forCellWithReuseIdentifier:@"YHYPicCollectionViewCell"];
        UILongPressGestureRecognizer *longGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(buttonLongPressed:)];
        [_myCollectionView addGestureRecognizer:longGesture];
        
        
<<<<<<< HEAD
        [self.numLabel removeFromSuperview];
        self.numLabel = [UILabel new];
        [cell addSubview:self.numLabel];
=======
        
        [cell3 addSubview:self.numLabel];
>>>>>>> 982ccfb85b77eadfd5494c8f30bd3225dd4fe1c6
        self.numLabel.textColor = [UIColor blackColor];
        self.numLabel.alpha = 0.6;
        self.numLabel.font = [UIFont systemFontOfSize:TEXTLABELFONT*TEXTWEIGHT];
        [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_myCollectionView.mas_bottom).offset(11 * AUTO_HEIGHT);
            make.left.mas_equalTo(cell3.mas_right).offset( - 50  * AUTO_WIDTH);
            make.height.mas_equalTo(15 * AUTO_WIDTH);
            [_myCollectionView reloadData];
            
        }];

        //        NSLog(@"zzzzzzz%ld",(unsigned long)_selectedPhotos.count);
        self.numLabel.text = [NSString stringWithFormat:@"%ld/9",(long)_selectedPhotos.count];
        
        
        
        //        TZTestCell *mycell = (TZTestCell *)[_myCollectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:_selectedPhotos.count inSection:0]];
        //        mycell.imageView.image = [UIImage imageNamed:@"jia"];
        
        
        [_myCollectionView reloadData];
        //            [_myTableView reloadData];
        
        return cell3;
        

        
        NSLog(@"zzzzzzz＝＝＝＝＝＝%ld",(unsigned long)_selectedPhotos.count);
        self.numLabel.text = [NSString stringWithFormat:@"%ld/9",(long)_selectedPhotos.count];
        

    }
    
    
    if (indexPath.section == 5) {
        
        
        YHYButtonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YHYButtonTableViewCell"];
        cell.delegate = self;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
        
    }
    
    return cell2;
    
}


- (void)goNext:(UIButton *)btu{
    [self.navigationController popViewControllerAnimated:YES];
}
//UICollectionView长按响应
- (void)buttonLongPressed:(UILongPressGestureRecognizer *)longPress
{
    switch (longPress.state) {
        case UIGestureRecognizerStateBegan:
        {
            
            NSIndexPath *selectedIndex = [[NSIndexPath alloc] init];
            CGPoint point = [longPress locationInView:_myCollectionView];
            selectedIndex = [_myCollectionView indexPathForItemAtPoint:point];
            [_myCollectionView beginInteractiveMovementForItemAtIndexPath:selectedIndex];
            TZTestCell *mycell = (TZTestCell *)[_myCollectionView cellForItemAtIndexPath:selectedIndex];
            if (selectedIndex.row == _selectedPhotos.count) {
                //左后一个不抖动
            }
            else{
                [self shakeAnimationForView:mycell.imageView point:point];
            }
            
        }
            break;
        case UIGestureRecognizerStateChanged:
        {
            [_myCollectionView updateInteractiveMovementTargetPosition:[longPress locationInView:_myCollectionView]];
        }
            break;
        case UIGestureRecognizerStateEnded:
        {
            // 啥意思打上注释:就是当他移动时，到边距ok，移动到一定位置就删除
            [_myCollectionView endInteractiveMovement];
            NSIndexPath *selectedIndex = [[NSIndexPath alloc] init];
            CGPoint point = [longPress locationInView:_myCollectionView];
            selectedIndex = [_myCollectionView indexPathForItemAtPoint:point];
            if (point.x < 50 || point.y < 50 || point.x > _itemWH * 3  - 30 || point.y > _itemWH * 3  - 40) {
                //          是图片
                [_selectedPhotos removeObjectAtIndex:_myindexPath.item];
                //   [_selectedPhotos removeObject:selectObject];
                //                 NSLog(@"%@",_selectedPhotos);
                //                NSLog(@"zzzzzzz%ld",(unsigned long)_selectedPhotos.count);
                
                
                // [_selectedPhotos removeObject:selectObject];
                NSLog(@"asasasas%@",_selectedPhotos);
                NSLog(@"zzzzzzz%ld",(unsigned long)_selectedPhotos.count);
                self.numLabel.text = [NSString stringWithFormat:@"%ld/9",(long)_selectedPhotos.count];
<<<<<<< HEAD
                NSLog(@"sssssssss%ld",(long)_myindexPath.row);
=======
                //                NSLog(@"sssssssss%ld",(long)_myindexPath.row);
               
                
                
                
                
                
                //
                TZTestCell *mycell = (TZTestCell *)[_myCollectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:_selectedPhotos.count inSection:0]];
                mycell.imageView.image = [UIImage imageNamed:@"jia"];
                
                
                
>>>>>>> 982ccfb85b77eadfd5494c8f30bd3225dd4fe1c6
                
                [_myCollectionView reloadData];
                
            }
            // NSLog(@"asasasas%@",_selectedPhotos);
            
            
        }
            
            break;
        default:
            [_myCollectionView cancelInteractiveMovement];
            break;
    }
    
    
}

- (void)shakeAnimationForView:(UIView *)view point:(CGPoint)point{
    //获取到当前的View
    CALayer *viewLayer = view.layer;
    //获取当前View位置
    CGPoint position = viewLayer.position;
    CGPoint x = CGPointMake(position.x + 9, position.y);
    CGPoint y = CGPointMake(position.x - 9, position.y);
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
    [animation setFromValue:[NSValue valueWithCGPoint:x]];
    [animation setToValue:[NSValue valueWithCGPoint:y]];
    [animation setAutoreverses:YES];
    [animation setDuration:0.06];
    [animation setRepeatCount:3];
    [viewLayer addAnimation:animation forKey:nil];
    
    
    
}





//通知响应方法
- (void)change:(NSNotification *)notification
{
    NSMutableArray *ar = [notification object];
    self.selectedPhotos = ar;
    NSLog(@"qqqq%@",ar);
    self.numLabel.text = [NSString stringWithFormat:@"%ld/9",(long)_selectedPhotos.count];
    [_myCollectionView reloadData];
    
}

#pragma mark - 发布协议
- (void)presentDelegate{
    [self.navigationController popViewControllerAnimated:YES];
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    NSLog(@"number:%ld", _selectedPhotos.count);
    if (_selectedPhotos.count >= 9) {
        return _selectedPhotos.count;
    }
    else{
        return _selectedPhotos.count + 1;
        //  [_myCollectionView reloadData];
    }
    
    
    
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
<<<<<<< HEAD
    if (indexPath.row == _selectedPhotos.count ) {
        self.cell.imageView.image = [UIImage imageNamed:@"jia"];
      
        
    }
    else {
        [self.cell.imageView removeFromSuperview];
        [self.cell addSubview:self.cell.imageView];
        self.cell.imageView.image = _selectedPhotos[indexPath.row];
        //self.cell.highlighted = YES;
=======
    
    
    if (indexPath.row == _selectedPhotos.count && _selectedPhotos.count <= 9) {
        
        //        YHYPictureCollectionViewCell *cell1 = [collectionView   dequeueReusableCellWithReuseIdentifier:@"YHYPicCollectionViewCell" forIndexPath:indexPath];
        TZTestCell *cell1 =  [collectionView dequeueReusableCellWithReuseIdentifier:@"TZTestCell" forIndexPath:indexPath];
        cell1.imageView.image = [UIImage imageNamed:@"jia"];
             
        return cell1;
    }
    else{
        TZTestCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"TZTestCell" forIndexPath:indexPath];
        
        if (!_selectedPhotos.count == 0) {
            cell.imageView.image = _selectedPhotos[indexPath.row];
            
            NSLog(@"-------%@", _selectedPhotos);
        }
        
        //        cell.imageI = _selectedPhotos[indexPath.row];
        
        
        return cell;
        
        
        
        
>>>>>>> 982ccfb85b77eadfd5494c8f30bd3225dd4fe1c6
    }
    
    
    
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"path   == ====== %@",indexPath);
    
    
    
    if (indexPath.row == _selectedPhotos.count) {
        
        
        [self pickPhotoButtonClick:nil];
        
    }
    else{
        //        YHYYHYYHYViewController *yhySeaVC = [YHYYHYYHYViewController new];
        
        SeaPictureViewController *yhySeaVC = [SeaPictureViewController new];
        yhySeaVC.seaArray  = [NSMutableArray arrayWithArray:_selectedPhotos];
        yhySeaVC.indexNumber = (NSInteger)indexPath.item;
        
        NSLog(@"sssssss%ld",yhySeaVC.indexNumber);
        //        [self presentViewController:yhySeaVC animated:YES completion:^{
        //
        //
        //        }];
        //        [self.navigationController presentViewController:yhySeaVC animated:YES completion:^{
        //
        //
        //        }];
        //
        [self.navigationController pushViewController:yhySeaVC animated:YES];
        
        
        
        
    }
    //  [_myCollectionView reloadData];//改
    
}
- (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    _myindexPath = indexPath;
    if ([collectionView numberOfItemsInSection:indexPath.section] <= 1) {
        return NO;
    }
    if (indexPath.row == _selectedPhotos.count) {
        return NO;
    }
    
    return YES;
}


- (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
    
    
    _tapIndexPath = sourceIndexPath;
    
    
    if (destinationIndexPath.row != _selectedPhotos.count) {
        
        
        NSString *selectObject = _selectedPhotos[sourceIndexPath.item];
        self.myindexPath = sourceIndexPath;
        //从资源数组中移除该数据
        [_selectedPhotos removeObject:selectObject];
        
        
        
        
        
        
        NSMutableArray *destinationArr = _selectedPhotos;
        [destinationArr insertObject:selectObject atIndex:destinationIndexPath.row];
        _selectedPhotos = [NSMutableArray arrayWithArray:destinationArr];
        
    }else{
#pragma mark -后改动的
        
        //        TZTestCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TZTestCell" forIndexPath:[NSIndexPath indexPathForItem:_selectedPhotos.count inSection:0]];
        //
        //            cell.imageView.image = [UIImage imageNamed:@"jia"];
        //
        
        
    }
    
    
    //    _cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TZTestCell" forIndexPath:[NSIndexPath indexPathForItem:_selectedPhotos.count inSection:0]];
    //
    //
    //    _cell.imageView.image = [UIImage imageNamed:@"jia"];
    
    [collectionView reloadData];
    
    
}


#pragma mark Click Event

- (IBAction)pickPhotoButtonClick:(UIButton *)sender {
    //    TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:5 delegate:self];
    NSInteger mum = 9;
    TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc]initWithMaxImagesCount:mum selectArr:_selectedPhotos delegate:self];
    imagePickerVc.selectCount = _selectedPhotos.count;
    //    NSLog(@"asas%ld",(long)imagePickerVc.selectCount);
    [self presentViewController:imagePickerVc animated:YES completion:nil];
    
    
}


- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray *)photos sourceAssets:(NSArray *)assets{
    [_selectedPhotos addObjectsFromArray:photos];
    //  NSLog(@"wwww%ld",(unsigned long)photos.count);
    //[self configCollectionView];
    NSLog(@"eeee=%ld",_selectedPhotos.count);
    _myCollectionView.contentSize = CGSizeMake(0, ((_selectedPhotos.count + 2) / 3 ) * (_margin + _itemWH));
    
    
    self.numLabel.text = [NSString stringWithFormat:@"%ld/9",(long)_selectedPhotos.count];
    
    [_myCollectionView reloadData];
    [self.myTableView reloadData];
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
   
    return CGSizeMake(_itemWH, _itemWH);
    
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(0, 0, 2.0 * AUTO_WIDTH, 0);
}






- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSLog(@"indepath ==%@",indexPath);
    
    if (indexPath.section == 0) {
        
        if (indexPath.row == 0) {
            
            DCPaymentView *payAlert = [[DCPaymentView alloc] init];
            payAlert.title = [NSString stringWithFormat:@"设计名称"];
            // [payAlert setTextFieldKeyBordToNum];
            payAlert.numOfContent = 5;
            [payAlert show];
            payAlert.completeHandle = ^(NSString *inputPwd) {
                
                self.name = [NSString stringWithFormat:@"%@", inputPwd];
                
                [_myTableView reloadData];
            };
            
        }
        
        if (indexPath.row == 1) {
            index = 3;
            self.customPicker = nil;
            self.customPicker = [[WSCustomPickerView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) dataArr:[NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6", nil]];
            self.customPicker.delegate = self;
            self.customPicker.titleStr = @"任务类型";
            [self.view addSubview:_customPicker];
            [self.customPicker showPicker];
            
        }
        
        
        if (indexPath.row == 2) {
            index = 2;
            self.customPicker = nil;
            self.customPicker = [[WSCustomPickerView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
            self.customPicker.delegate = self;
            self.customPicker.titleStr = @"任务地址";
            [self.view addSubview:_customPicker];
            [self.customPicker showPicker];
        }
        //        if (indexPath.row ==3) {
        //            NSLog(@"详细地址");
        //        }
        
        if (indexPath.row == 3) {
            DCPaymentView *payAlert = [[DCPaymentView alloc] init];
            payAlert.title = [NSString stringWithFormat:@"任务面积"];
            [payAlert setTextFieldKeyBordToNum];
            payAlert.numOfContent = 5;
            [payAlert show];
            payAlert.completeHandle = ^(NSString *inputPwd) {
                
                _sizeL = [NSString stringWithFormat:@"%@", inputPwd];
                
                [_myTableView reloadData];
                
            };
            
        }
        
        
    }
    
    
#pragma mark - 自己需要
    
    //    if (indexPath.section == 1) {
    //        if (indexPath.row == 0) {
    //            NSLog(@"设计要求");
    //            _yhy= [YHYSelectViewController new];
    //
    //            _yhy.mydelegate = self;
    //            _myAppDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    //            // [_myAppDelegate.window addSubview:self.view];
    //
    //            _myBackBigView  = [[UIView alloc]initWithFrame:CGRectMake(0, 58 * AUTO_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT)];
    //            _myBackBigView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3];
    //            [_myAppDelegate.window addSubview:_myBackBigView];
    //            //    self.shareBackGroundView = _myBackBigView;
    //            //    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    //            //    [delegate.window addSubview:_shareBackGroundView];
    //            [_myBackBigView.window addSubview:_yhy];
    //            [_yhy mas_makeConstraints:^(MASConstraintMaker *make) {
    //                make.centerXWithinMargins.mas_equalTo(self.view);
    //                make.centerYWithinMargins.mas_equalTo(self.view);
    //                make.height.mas_equalTo(846/3 * AUTO_HEIGHT);
    //                make.width.mas_equalTo(823/3 * AUTO_WIDTH);
    //
    //            }];
    //
    //
    //            //  [self.view addSubview:_yhy];
    //
    //        }
    //        if (indexPath.row == 1) {
    //            index = 4;
    //            self.customPicker = nil;
    //            self.customPicker = [[WSCustomPickerView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) dataArr:[NSArray arrayWithObjects:@"a",@"b",@"3",@"4",@"5",@"6", nil]];
    //            self.customPicker.delegate = self;
    //            self.customPicker.titleStr = @"设计要求";
    //            [self.view addSubview:_customPicker];
    //            [self.customPicker showPicker];
    //
    //        }
    //               if (indexPath.row == 3) {
    //
    //        }
    //    }
    
    
    if (indexPath.section == 3) {
        if (indexPath.row == 0) {
            
            index = 5;
            self.customPicker = nil;
            self.customPicker = [[WSCustomPickerView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) dataArr:[NSArray arrayWithObjects:@"1-2年",@"1-3年",@"2-3年",@"4",@"5",@"6", nil]];
            self.customPicker.delegate = self;
            self.customPicker.titleStr = @"设计经验";
            [self.view addSubview:_customPicker];
            [self.customPicker showPicker];
            
            
        }
    }
    if (indexPath.row == 1) {
        NSLog(@"元");
        index = 6;
        DCPaymentView *payAlert = [[DCPaymentView alloc] init];
        payAlert.title = [NSString stringWithFormat:@"项目总价"];
        [payAlert setTextFieldKeyBordToNum];
        payAlert.numOfContent = 4;
        [payAlert show];
        payAlert.completeHandle = ^(NSString *inputPwd) {
            
            self.priceL = [NSString stringWithFormat:@"%@元", inputPwd];
            
            [_myTableView reloadData];
            
        };
        
    }
    
}

//协议
- (void)presentDiemess:(NSInteger)arraynum{
    _selectArray = arraynum;
    [_yhy removeFromSuperview];
    [_myBackBigView removeFromSuperview];
    [_myTableView reloadData];
}
//任务类型 单滑动
- (void)sendAddressInfo:(NSString *)address{
    if (index == 1) {
        
    }
    if (index == 2) {
        
        _addressL = address;
        
    }
    if (index == 3) {
        
        _styleL=address;
        
    }
    if (index == 4) {//风格要求
        _styleRequire = address;
    }
    if (index == 5) {
        _yearL = address;
    }
    
    [_myTableView reloadData];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==1) {
        //  if (indexPath.row == 0) {
        return 80 * AUTO_HEIGHT;
        //  }
        
    }
    if (indexPath.section == 2) {
        return 310 * AUTO_HEIGHT;
    }
    if (indexPath.section == 4) {
        //        NSInteger a = _selectedPhotos.count;
        if (_selectedPhotos.count < 3 ) {
            a = 0;
        }
        if (_selectedPhotos.count >= 3 && _selectedPhotos.count <= 5) {
            a = 1;
        }
        if ( _selectedPhotos.count > 5 && _selectedPhotos.count <= 9) {
            a = 2;
        }
        return 150 * AUTO_HEIGHT  + (150 * AUTO_HEIGHT* (a));
    }
    if (indexPath.section == 5) {
        return 140 * AUTO_HEIGHT;
    }
    return ROWHEIGHT;
}

- (void)Back:(UIButton*)btu{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
